package data;

import data.GeneralDefinitions.ClusteringPriorityParameters;
import data.GeneralDefinitions.OrderingParameters;

public class LUNPerTimeUnit {

	private LUN _lun;
	private TimeUnit _timeUnit;
	private double _totalKbWritten;
	private double _totalKbRead;
	private double _numOfReads;
	private double _numOfWrites;
	private Data _data;
	private int _lunId;
	private int _timeUnitId;


    public LUNPerTimeUnit(LUN _lun, TimeUnit _timeUnit, double _totalKbWritten, double _totalKbRead, double _numOfReads, double _numOfWrites) {
    	this._data = null;
    	this._lunId = _lun.get_id();
    	this._timeUnitId = _timeUnit.get_id();
        this._lun = _lun;
        this._timeUnit = _timeUnit;
        this._totalKbWritten = _totalKbWritten;
        this._totalKbRead = _totalKbRead;
        this._numOfReads = _numOfReads;
        this._numOfWrites = _numOfWrites;
    }

    public LUNPerTimeUnit(Data data, int lun, int timeunit, double _totalKbWritten, double _totalKbRead, double _numOfReads, double _numOfWrites) {
    	this._data = data;
    	this._lunId = lun;
    	this._timeUnitId = timeunit;
        this._lun = null;
        this._timeUnit = null;
        this._totalKbWritten = _totalKbWritten;
        this._totalKbRead = _totalKbRead;
        this._numOfReads = _numOfReads;
        this._numOfWrites = _numOfWrites;
    }

    public LUNPerTimeUnit(Data data, LUN lun, int timeunit, double _totalKbWritten, double _totalKbRead, double _numOfReads, double _numOfWrites) {
    	this._data = data;
    	this._lunId = lun.get_id();
    	this._timeUnitId = timeunit;
        this._lun = lun;
        this._timeUnit = null;
        this._totalKbWritten = _totalKbWritten;
        this._totalKbRead = _totalKbRead;
        this._numOfReads = _numOfReads;
        this._numOfWrites = _numOfWrites;
    }


	public LUN get_lun() {
		if (_lun == null && _data!=null){
//			System.out.println("LUNPerTimeUnit, get_lun: getting LUN");
			_lun = _data.getLUN(_lunId);
		}
		return _lun;
	}


	public TimeUnit get_timeUnit() {
		if (_timeUnit == null && _data!=null){
//			System.out.println("LUNPerTimeUnit, get_timeUnit: getting timeUnit");
			_timeUnit = _data.getTimeUnit(_timeUnitId);
		}
		return _timeUnit;
	}


	public double get_totalKbWritten() {
		return _totalKbWritten;
	}


	public double get_totalKbRead() {
		return _totalKbRead;
	}

	public double get_numOfReads() {
		return _numOfReads;
	}


	public double get_numOfWrites() {
		return _numOfWrites;
	}


    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final LUNPerTimeUnit other = (LUNPerTimeUnit) obj;
        if (this._lun != other._lun && (this._lun == null || !this._lun.equals(other._lun))) {
            return false;
        }
        if (this._timeUnit != other._timeUnit && (this._timeUnit == null || !this._timeUnit.equals(other._timeUnit))) {
            return false;
        }
        if (this._totalKbWritten != other._totalKbWritten) {
            return false;
        }
        if (this._totalKbRead != other._totalKbRead) {
            return false;
        }
        if (this._numOfReads != other._numOfReads) {
            return false;
        }
        if (this._numOfWrites != other._numOfWrites) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this._lun != null ? this._lun.hashCode() : 0);
        hash = 47 * hash + (this._timeUnit != null ? this._timeUnit.hashCode() : 0);
        hash = (int) (47 * hash + this._totalKbWritten);
        hash = (int) (47 * hash + this._totalKbRead);
        hash = (int) (47 * hash + this._numOfReads);
        hash = (int) (47 * hash + this._numOfWrites);
        return hash;
    }

	public Double getField(ClusteringPriorityParameters clusterType) {
		if (clusterType == ClusteringPriorityParameters.kbRead)
			return _totalKbRead+0.0;
		else if (clusterType == ClusteringPriorityParameters.kbWritten)
			return _totalKbWritten+0.0;
		else if (clusterType == ClusteringPriorityParameters.numOfReads)
			return _numOfReads+0.0;
		else if (clusterType == ClusteringPriorityParameters.numOfWrites)
			return _numOfWrites+0.0;
		return null;
	}

	public Double getField(OrderingParameters orderingParameter) {
		if (orderingParameter == OrderingParameters.kbRead)
			return _totalKbRead+0.0;
		else if (orderingParameter == OrderingParameters.kbWritten)
			return _totalKbWritten+0.0;
		return null;
	}


}
